<template>
  <div class="home-classic">
      <h2>热门歌手</h2>
      <div class="wrapper" ref="wrapper">
          <!-- 滚动需要的容器 -->
          <ul class="content" ref="content">
              <li v-for="(item, index) in listData" :key="index" @click="selectItem(item)">
                  <div class="cover">
                      <van-image :src="item.singer_pic" radius="1rem" />
                  </div>
                  <span>{{ item.singer_name }}</span>
              </li>
          </ul>
      </div>
  </div>
</template>
<script>
import { betterScrollHorizontal } from "../../common/betterScroll.js"
export default {
  data() {
      return {
          listData: []
      }
  },
  created() {
      this.getSongListData()
  },
  methods: {
      getSongListData() {
          this.$request('get', '/singer/list',{
              id:59,
              pageSize:10
          }).then((res) => {
                  console.log(res)
                  if (res.result == 100) {
                      this.listData = res.data.list;
                  }
                  betterScrollHorizontal(
                      this,
                      this.$refs.wrapper,
                      this.$refs.content,
                      this.listData.length,
                      10
                  );
              });
      },
      selectItem(item) {
          const id = item.singer_mid;
          // console.log(id);
          this.$store.commit('saveSinger',item)
          this.$router.push(`/singerhome/${id}`)
      }
  },
};
</script>

<style scoped>
/* .home-recommond>ul{
  display: flex;
  flex-wrap: wrap;
}
.home-recommond>ul>li{
  width: calc((100% - 1rem) / 3 * 1);
}
.home-recommond>ul>li:nth-of-type(3n+2){
  margin-left: 0.5rem;
  margin-right: 0.5rem;
} */
.cover {
  position: relative;
}

.wrapper {
  width: 100%;
  /*容器的宽度就是屏幕的宽度 */
  overflow: hidden;
}

/*content内容区的宽度要大于wrapper容器的宽度，12个列表项 */
/* ul.content{
  width: calc(12 * 10rem);
} */
ul.content li {
  /*li默认是块级元素，修改为行内元素，但是要具备块级元素的特性*/
  display: inline-block;
  width: 10rem;
  vertical-align: top;
  /*垂直方向的位置*/
}

/* li里面有两个元素：div和span，所以使用通配符* */
ul.content li * {
  margin: 0 0.1rem;
  /*里面的元素与li的边距有个间距*/
}

ul.content li>span {
  font-size: 0.8rem;
  color: #54493b;
}</style>
